<?php
require_once("header.php");
require_once("model/DB.php");
require_once("model/Kid.php");
require_once("model/User.php");
require_once("model/Grade.php");
require_once("model/Kid.php");
require_once("model/Class.php");
require_once("function/teacher.login.php");

$parents = User::getUser("type","parent");
$grades = Grade::getGrade();
$class = Classes::getClassByTeacher($_SESSION['userid']);
$class_id = $class['id'];
$kids = Kid::getKid('class_id',$class_id);


$grades = Grade::getGrade();

?>
<script>


$(document).ready(function(){
	$("#kid_table").tablesorter( 
		{widthFixed: true, widgets: ['zebra']} 
	).tablesorterPager({container: $("#pager")});
	


});
function ajax_upload(id)
{
	$("#upload_indicator").show();

	$.ajaxFileUpload
	(
		{
			url:'upload.php?path=avatar&id='+id,
			secureuri:false,
			fileElementId:id+'_image',
			dataType: 'json',
			success: function (data, status)
			{
				if(typeof(data.error) != 'undefined')
				{
					if(data.error != '')
					{
						alert(data.error);
					}else
					{
						
						
                        $("#image").val("");
						window.location = window.location;

					}
				}
			},
			
			error: function (data, status, e)
			{
				alert("Error: " + data.responseText.toString());				
			}
		}
	)
	
	return false;
}
</script>
<center>
<table id="admin_detail" cellspacing="0" cellpadding="0" >
<tr>
<td id="left_bar" style="border-right:1px solid black;text-align:center; width:100px;">

<br>
<a class="admin_left" href="teacher.php">Home</a>

</td>
<td>
<div id="kid_list">
<table id="kid_table" class="tablesorter">
	<thead>
		<tr><td>Avatar</td><td>Name</td><td>Gender</td><td>Nationality</td><td>Age</td><td>Parent</td><td>Action</td></tr>
	</thead>
	<tbody>
		<?php
		if($kids){
			
		
			
			foreach($kids as $kid){

				$kid['age'] = floor((time()-strtotime($kid['age']))/31536000);
				?>
				<tr style="vertical-align:middle;"><td><img src="avatar/<?php echo $kid['avatar']; ?>" width="50" height="50"></td><td><?php echo $kid['name']; ?></td><td><?php echo $kid['gender']; ?></td><td><?php echo $kid['nation']; ?></td><td><?php echo $kid['age']; ?></td><td><?php echo $kid['username'] ?></td><td><input class="file" type="file" id="<?php echo $kid['id'] ?>_image" name="image" size=0 onchange="if($('#image').val() != '') ajax_upload(<?php echo $kid['id'];?>); " /></td></tr>
				<?php 
			}
		}
		?>
	</tbody>
</table>


<div id="pager" class="pager" style="width:800px;margin-left:5px;margin-top:15px">
					<form>
						<img class="first" src="images/first.png"/>
						<img class="prev" src="images/prev.png"/>
						<input class="pagedisplay" type="text"/>
						<img class="next" src="images/next.png"/>
						<img class="last" src="images/last.png"/>
						<select id="pagesize" class="pagesize">
							 <option value="10" >10</option>
							 <option value="15" >15</option>
							 
						</select>
					</form>
</div>
</div>
<div id="kid_form" style="display:none">
<form class="add_kid">
<table>
	<tr>
		<td>*Title</td><td><input type="text" class="title"></td>
	</tr>	

	<tr>
		<td><input type="submit" value="Save"></td><td><input type="button" class="cancel" value="Cancel"></td>
		<input type="hidden" class="id" value="">
	</tr>
</table>
</form>
</div>
<div id="add_form">
</div>
</td>
</tr>
</table>
</center>